<?php
if ($leave_record > 0) {
	$page = $this->uri->segment(4);
	$page = $page ? $page : 0;
	echo form_open('record/delete_records', $page);
	?>

	<div class="cleaner"></div>
	<?php $this->load->view('incs/num_perpage'); ?>
	<table class="display" id="search">
		<thead>
			<tr class="success">
				<th class="sorting_1 sorting">N&ordm;&nbsp;</th>
				<th class="td-check"><?php echo form_checkbox(array('name' => 'checker', 'id' => 'check_header')); ?></th>
				<th>Staff Name</th>
				<th class="td-check">Gender</th>
				<th>Type of Leave</th>
				<th>Reason</th>
				<th>Start Date</th>
				<th>End Date</th>
				<th>Duration</th>
				<th>Validated</th>
				<th class="td-check">Status</th>
				<th>Dept</th>
				<th class="td-check">Action</th>
			</tr>
		</thead>
		<tbody>
			<?php
			// column id
			$id = 1;
			if ($this->uri->segment(4)) {
				$id = $this->uri->segment(4) + 1;
			} else {
				$id = 1;
			}
			foreach ($leave_record as $data):
				//duration of leaving think as Day
				$duration = $data->duration;
				if ($duration > 1) {
					$day = 'Days';
				} else {
					$day = 'day';
				}
				/* Display as Month	 * uss substr() to trim string for database of date */
				$str_date = substr($data->start_date, 6, -3);
				$months = array('January', 'February', 'Match', 'April', 'May', 'June', 'July', 'Auegst', 'September', 'October', 'November', 'December');
				for ($i = 0; $i < count($months); $i++) {
					if ($i == $str_date) {
						$month = $months[$i];
					}
				}
				?>
				<tr class="tbl">
					<td class="sorting_1"><?php echo $id++; ?></td>
					<td class="td-check"><?php echo form_checkbox(array('class' => 'check_value', 'id' => 'rcd_check', 'name' => 'rcdChecked[]'), $data->rcd_id); ?></td>
					<td class="input-name"><span class="txt-bold"><?php echo strtoupper($data->emp_lname) . ' ' . ucfirst($data->emp_fname); ?></span></td>
					<td class="td-check"><span class="txt-gender"><?php echo $data->emp_gender; ?></span></td>		
					<td><?php echo $data->stl_name; ?></td>
					<td><?php echo $data->lea_reason; ?></td>
					<td><?php echo $data->start_date; ?></td>
					<td><?php echo $data->end_date; ?></td>
					<td><?php echo $duration . nbs() . $day . br() . $data->hour . nbs() . 'Hours'; ?></td>
					<?php
					$this->db->select("emp_lname,emp_fname");
					$this->db->from("pnc_employee");
					$this->db->where("staff_id", $data->val_id);
					$validator = $this->db->get();
					if ($validator->num_rows() > 0) {
						foreach ($validator->result() as $arr) {
							?>
							<td><?php echo strtoupper($arr->emp_lname) . nbs(2) . ucfirst($arr->emp_fname); ?></td>
							<?php
						}
					} else {
						?>
						<td>&nbsp;</td>
					<?php } ?>
					<td class="td-check">
						<?php
						if ($data->rcd_status == 1) {
							echo anchor('record/approved/' . $data->rcd_status . '/' . $data->rcd_id . '/' . $data->staff_id, img('bootstrap/images/tick.png'), 'title="Disapprove"');
						} else {
							echo anchor('record/approved/' . $data->rcd_status . '/' . $data->rcd_id . '/' . $data->staff_id, img('bootstrap/images/notice.png'), 'title="Approve"');
						}
						?>
					</td>
					<td><?php echo $data->dept_name; ?></td>
					<td class="td-check"><?php
				$del = img('bootstrap/images/del.png');
				$edit = img('bootstrap/images/edit.gif');
				echo anchor('record/edit_record/' . $data->lea_id . '/' . $data->rcd_id, $edit, 'title="Edit"') . ' | ' . anchor('record/delete/' . $data->rcd_id . '/' . $data->staff_id, $del, 'title="Delete" onclick="return confirm(\'Are you sure want to delete?\');"');
						?>
					</td>
				</tr>
			<?php endforeach; ?>
		</tbody>
	</table>


	<table>
		<?php
		if ($pagination) {
			?>
			<tr>
				<td>
					<span class="pull-right control">
						<?php
						echo form_submit('btn_del_record', 'Delete', 'onclick="return confirm(\'Are you sure?\');" class="btn btn-info"') . nbs(2) . anchor('record/add_record', form_button('btn_add_rcd', 'Add Record', 'class="btn btn-info"'));
						?>
					</span></td>
				<td>
					<span class="pagination-link"><?php echo $pagination; ?></span>
				</td>
			</tr>
	<?php } else { ?>

			<tr>
				<td>
					<span class="pull-right control">
						<?php
						echo form_submit('btn_del_record', 'Delete', 'onclick="return confirm(\'Are you sure?\');" class="btn btn-info"') . nbs(2) . anchor('record/add_record', form_button('btn_add_rcd', 'Add Record', 'class="btn btn-info"'));
						?>
					</span></td>
			</tr>
	<?php } ?>
	</table>

	<?php
	echo form_close();
} else {
	?>
	<table>
		<tr>
			<td><?php echo "Data not found!!"; ?></td>
		</tr>
	</table>

<?php } ?>